1 /*
2 Copyright (c)
2014 Andrew Jones, Dario Seyb
3  Based
on 'Spriter2Unity' python code by Malhavok
4
5 Permission
is hereby granted, free of charge, to any person obtaining a copy
6 of
this software and associated documentation files (the "Software"), to deal
7 in
the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software
is
10 furnished to
do so, subject to the following conditions:
11
12 The above copyright notice and
this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */

23
24 using
System;
25 using
System.Collections.Generic;
26 using
System.Linq;
27 using
System.Text;
28 using
System.Xml;
29
30 namespace
Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {

32     ///
<summary>
33     ///
Base class for all timeline keys.
34     ///
</summary>
35     
public class TimelineKey : Key
36     {

37         ///
<summary>
38         ///
Reference to the timeline the key is on.
39         ///
</summary>
40         
public Timeline Timeline { get; private set; }
41
42         ///
<summary>
43         ///
The interpolation type to use for this key.
44         ///
</summary>
45         
public CurveType CurveType { get; private set; }
46
47         ///
<summary>
48         ///
Parameters to use for interpolation (quadratic and qubic at the moment)
49         ///
</summary>
50         
public float[] CurveParams { get; private set; }
51
52         
public TimelineKey(XmlElement element, Timeline timeline)
53             :
base(element)
54         {
55             Parse(element, timeline);
56         }
57
58         
protected virtual void Parse(XmlElement element, Timeline timeline)
59         {
60             
string curveString = element.GetString("curve_type", "linear");
61             
switch (curveString)
62             {
63                 
case "instant":
64                     CurveType = Spriter.CurveType.Instant;
65                     
break;
66                 
case "linear":
67                     CurveType = Spriter.CurveType.Linear;
68                     
break;
69                 
case "quadratic":
70                     CurveType = Spriter.CurveType.Quadratic;
71                     
break;
72                 
case "cubic":
73                     CurveType = Spriter.CurveType.Cubic;
74                     
break;
75                 
case "quartic":
76                     CurveType = Spriter.CurveType.Quartic;
77                     
break;
78                 
case "quintic":
79                     CurveType = Spriter.CurveType.Quintic;
80                     
break;
81                 
default:
82                     CurveType = Spriter.CurveType.INVALID;
83                     
break;
84             }
85
86             Timeline = timeline;
87
88             GetCurveParams(element);
89         }
90
91         
void GetCurveParams(XmlElement element)
92         {
93             
//Get curve parameters using a bit of XPath, order using LINQ
94             
//XPath 1.0 doesn't support regex - should match all attributes with names matching "c[0-9]+"
95             
var curveParams = element.SelectNodes("@*[starts-with(name(), 'c') and string(number(substring(name(),2))) != 'NaN']")
96                 .OfType<XmlAttribute>()
97                 .OrderBy(attr => attr.Name);
98
99             
//Cast the values to float and convert to an array
100             CurveParams = curveParams
101                 .Select(attr =>
float.Parse(attr.Value))
102                 .ToArray();
103         }
104     }
105 }


Base class for all timeline keys.

Reference to the timeline the key is on.

The interpolation type to use for this key.

Parameters to use for interpolation (quadratic and qubic at the moment)

Get curve parameters using a bit of XPath, order using LINQ

XPath 1.0 doesn't support regex - should match all attributes with names matching "c[0-9]+"

Cast the values to float and convert to an array




Trò chơi đua xe động vật trong UNITY Engine 114.683 lượt xem

Gõ tìm kiếm nhanh...